﻿using AutoMapper;
using BasicInformation.API.Application.Command.VehicleCommand;
using BasicInformation.Domain;
using BasicInformation.Infrastructure.Interface;
using MediatR;

namespace BasicInformation.API.Application.CommandHandler.VehicleCommandHandler
{
    public class VehicleUpdateCommandHandler : IRequestHandler<VehicleUpdateCommand, int>
    {
        private readonly IVehicleRepository vehicleRepository;
        private readonly IMapper mapper;

        public VehicleUpdateCommandHandler(IVehicleRepository vehicleRepository, IMapper mapper)
        {
            this.vehicleRepository = vehicleRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(VehicleUpdateCommand request, CancellationToken cancellationToken)
        {
            var info = mapper.Map<Vehicle>(request);
            return await vehicleRepository.Update(info);
        }
    }
}
